package com.dragon.common.feign;

import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
import com.dragon.common.feign.core.DragonFeignInnerRequestInterceptor;
import com.dragon.common.feign.core.DragonFeignRequestCloseInterceptor;
//import com.dragon.common.feign.sentinel.ext.DragonSentinelFeign;
import feign.Feign;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.DragonFeignClientsRegistrar;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;

/**
 * @date: 2024/8/8 11:17
 * @author: ybl
 */

@Configuration(proxyBeanMethods = false)
@Import(DragonFeignClientsRegistrar.class)
//@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
public class DragonFeignAutoConfiguration {

//    @Bean
//    @Scope("prototype")
//    @ConditionalOnMissingBean
//    @ConditionalOnProperty(name = "feign.sentinel.enabled")
//    public Feign.Builder feignSentinelBuilder() {
//        return DragonSentinelFeign.builder();
//    }

    /**
     * add http connection close header
     *
     * @return
     */
    @Bean
    public DragonFeignRequestCloseInterceptor DragonFeignRequestCloseInterceptor() {
        return new DragonFeignRequestCloseInterceptor();
    }

    /**
     * add inner request header
     *
     * @return DragonFeignInnerRequestInterceptor
     */
    @Bean
    public DragonFeignInnerRequestInterceptor DragonFeignInnerRequestInterceptor() {
        return new DragonFeignInnerRequestInterceptor();
    }

}
